-- ATUALIZA TABE F_OFCONS QUANDO ESSA 'E ALTERADA
CREATE OR REPLACE TRIGGER T_ATS_DETOFCONS 
AFTER UPDATE  ON ATS_DETOFCONS FOR EACH ROW
DECLARE
v_oflanc NUMBER;
BEGIN
      
    IF :NEW.DFC_QTDEMP <> :OLD.DFC_QTDEMP THEN
       UPDATE ATS_OFCONS SET OFC_QTDEMP = OFC_QTDEMP + (:NEW.DFC_QTDEMP - :NEW.DFC_QTDEMP) 
       WHERE OFC_CODIGO= :NEW.DFC_COFCON;
    END IF; 
    
    IF :NEW.DFC_QTDCON <> :OLD.DFC_QTDCON THEN

       UPDATE ATS_OFCONS SET OFC_QTREAL = OFC_QTREAL + (:NEW.DFC_QTDCON - :NEW.DFC_QTDCON) 
       WHERE OFC_CODIGO= :NEW.DFC_COFCON;

    END IF;  
END;
/